<?php
    class contentModel extends Model{
		//获取这条新闻信息
		public function getchAll(){  //获取id相同的信息信息
			$id=$_GET['id'];
			$sql="SELECT * FROM `news` WHERE id='{$id}'";
			$rs=$this->db->fetchRow($sql);
			return $rs;
		}
		//获取这条新闻的留言数
		public function getNumber(){
		    $id=$_GET['id'];
		    $sql="select count(*) from news where pid='{$id}'";
		    $rs=$this->db->fetchRow($sql);
		    return $rs[0];//返回结果数
	    }
		//发布新闻留言
		public function liuyan(){
			$pid=$_GET['id'];
		    $content=$_POST['content'];
		    $date=date('Y-m-d H:i:s');
			session_start();
			$reporter=$_SESSION['user'];
			$sql="INSERT INTO `news`(`id`, `pid`, `title`, `source`, `date`, `reporter`, `content`, `editor`, `hot`) VALUES (null,'{$pid}',null,null,'{$date}','{$reporter}','{$content}',null,null)";
		    return $rs=$this->db->query($sql);
		}
		//获取新闻留言数据
		public function getAll(){
	      $pid=$_GET['id'];
		  $sr=$this->db->fetchAll("SELECT * FROM `news` WHERE pid='{$pid}'");
		  return $sr;
		}
		//回复留言
		public function huihu(){
			$m_id=$_GET['id'];
			$m_pid=$_GET['pid'];
			$content=$_POST['content'];
		    $date=date('Y-m-d H:i:s');
			session_start();
			$username=$_SESSION['user'];
			$sql="INSERT INTO `message`(`id`, `m_id`, `m_pid`, `username`, `content`, `date`) VALUES (null,'{$m_id}','{$m_pid}','{$username}','{$content}','{$date}')";
		return $rs=$this->db->query($sql);
		}
		//获取回复留言数据
		public function gethuihu(){
		  $ss=$this->db->fetchAll("SELECT * FROM `message`");
		  return $ss;
		}
		//获取news表的新闻标题全部数据
		public function newstitle(){
		    $rs=$this->db->fetchAll("select * from news where pid=0");
		    return $rs;
	    }
  }
?>